/** @type {import('next').NextConfig} */

const isProd = process.env.BUILD_ENV === 'prod';
// const assetPrefix = isProd ? 'https://resume.cjasen.com' : undefined;
const nextConfig = {
  // assetPrefix,
  productionBrowserSourceMaps: false,
  output: 'standalone',
  reactStrictMode: false,
  compiler: {
    styledComponents: true,
  },
  experimental: {
    forceSwcTransforms: true,
    scrollRestoration: true,
  },
  env: {
    BUILD_ENV: process.env.BUILD_ENV,
  },
  images: {
    formats: ['image/webp'],
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'resume.cjasen.com',
        pathname: '**',
      },
    ],
  },
  async redirects() {
    return [
      {
        source: '/index',
        destination: '/',
        permanent: true,
      },
      {
        source: '/fanwen',
        destination: '/fanwen/1',
        permanent: true,
      },
      {
        source: '/recommend',
        destination: '/recommend/1',
        permanent: true,
      },
      {
        source: '/muban',
        destination: '/muban/list',
        permanent: true,
      },
      {
        source: '/cv/:type',
        destination: '/cv/:type/1',
        permanent: true,
      },
      {
        source: '/cv',
        destination: '/cv/list',
        permanent: true,
      },
    ];
  },
  // webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
  //   // 将 'source-directory' 替换为你实际的外部组件目录路径。
  //   const externalComponentsDirectory = path.resolve(
  //     __dirname,
  //     "../../components"
  //   );
  //   config.module.rules
  //     .find(({ oneOf }) => !!oneOf)
  //     .oneOf.filter(({ use }) => JSON.stringify(use)?.includes("css-loader"))
  //     .reduce((acc, { use }) => acc.concat(use), [])
  //     .forEach(({ options }) => {
  //       if (options.modules) {
  //         options.modules.getLocalIdent = (
  //           context,
  //           localIdentName,
  //           localName,
  //         ) => {
  //           return generateScopedName(localName, context.resourcePath);
  //         };
  //       }
  //     });
  //   config.module.rules.push({
  //     test: /\.tsx?$/,
  //     include: [externalComponentsDirectory],
  //     use: [
  //       {
  //         loader: "babel-loader", // 如果你已经配置了使用 SWC，可以使用 'next-babel-loader'。
  //         options: {
  //           presets: ["next/babel"],
  //         },
  //       },
  //     ],
  //   });
  //   return config;
  // },
};

module.exports = nextConfig;

// Injected content via Sentry wizard below

// const { withSentryConfig } = require("@sentry/nextjs");

// module.exports = withSentryConfig(module.exports, {
//   org: "c418cda3c879",
//   project: "baijie",

//   // Only print logs for uploading source maps in CI
//   silent: !process.env.CI,

//   // For all available options, see:
//   // https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

//   // Upload a larger set of source maps for prettier stack traces (increases build time)
//   widenClientFileUpload: true,

//   // Transpiles SDK to be compatible with IE11 (increases bundle size)
//   transpileClientSDK: true,

//   // Uncomment to route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
//   // This can increase your server load as well as your hosting bill.
//   // Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
//   // side errors will fail.
//   // tunnelRoute: "/monitoring",

//   // Hides source maps from generated client bundles
//   hideSourceMaps: true,

//   // Automatically tree-shake Sentry logger statements to reduce bundle size
//   disableLogger: true,

//   // Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
//   // See the following for more information:
//   // https://docs.sentry.io/product/crons/
//   // https://vercel.com/docs/cron-jobs
//   automaticVercelMonitors: true,
// });
